
**********************************************************************************************************************************
*** REPLICATION FILE FOR "LUCK OF THE DRAW"
*** Brian Williams & Indridi H. Indridason
*** Place all replication files in the same directory
**********************************************************************************************************************************

*** Set directory to where replication files are saved
cd "C:\Projects\Private Member Bills\PSRM Replication files"

*** Install matmap for doing operations on matrices
*** Written by Nicholas J. Cox
*** Available at https://ideas.repec.org/c/boc/bocode/s413501.html

net install matmap, from(http://fmwww.bc.edu/RePEc/bocode/m)

*** NOTE: Requires mat2txt2.ado
*** Written by Keith Kranker
*** Available at: https://code.google.com/archive/p/kk-adofiles/source/default/source (only in zip file)
*** ado file and hlp file have been uploaded to the dataverse
*** Download mat2txt.ado and save in your ".ado folder"
*** To find where your ".ado folder" is located, type 'sysdir' in Stata


***********************************
*** TABLE 1 & DATA FOR FIGURE 1-5
***********************************
set more off
log using "PSRM_replication.log", replace

use "PSRM_table1.dta", clear

*** Data for FIGURE 1
tab placed_ballot if govt==1 & minister==0 & ranked==0
tab placed_ballot if support_party==1 & minister==0 & ranked==0
tab placed_ballot if govt==0 & support_party==0 & minister==0 & ranked==0
tab newbill if govt==1 & minister==0 & ranked==0
tab newbill if support_party==1 & minister==0 & ranked==0
tab newbill if govt==0 & support_party==0 & minister==0 & ranked==0
*** Share of placed and new bills are entered manually in PMB_figures.tex

**** Create data for histogram in FIGURE 2
tab attempts if attempts>0 & sh_a~=. & ranked_member~=1, matcell(attempts)
tab unique if unique>0 & sh_a~=. & ranked_member~=1, matcell(unique)
matrix list attempts
matrix list unique

scalar j=rowsof(attempts)-rowsof(unique)
local j=rowsof(attempts)
display `j'
matrix fill=J(j,1,.)
matrix unique=unique\fill
matrix c=J(18,1,.)
forvalues i=1/`j' {
	matrix c[`i',1]=`i'
	if (unique[`i',1]>100 & unique[`i',1]~=.) {
		matrix unique[`i',1]=70
		}
	if (unique[`i',1]>70 & unique[`i',1]~=.) {
		matrix unique[`i',1]=65
		}
	}
matrix nobills=c,attempts,unique
matrix list nobills
matrix colnames nobills = no attempts1 unique1
matrix list nobills
* Saves data in CSV file to used by PMB_figures.tex to create histogram
mat2txt2 nobills using "hist_attemptNEW.csv", replace comma

*********************************************************************************
*FIGURE 3: Histogram of margin for placed a bill on the ballot or not
*********************************************************************************
twoway (histogram margin if placed_b==0 & cvs1~=. & ranked==0, color(green)) ///
 (histogram margin if placed_b==1 & cvs1~=. & ranked==0,  fcolor(none) lcolor(black)), legend(order(1 "No" 2 "Yes" ))
* Output for Latex
twoway__histogram_gen margin if placed_b==0 & cvs1~=. & ranked==0, start(-.732) width(.04) gen(dist_m_0 xm0)
twoway__histogram_gen margin if placed_b==1 & cvs1~=. & ranked==0, start(-.732) width(.04) gen(dist_m_1 xm1) 
matrix margingraph=J(41,4,.)
forvalues i=1/36 {
	matrix margingraph[`i',1]=xm0[`i']
	matrix margingraph[`i',2]=dist_m_0[`i']
	matrix margingraph[`i',3]=xm1[`i']
	matrix margingraph[`i',4]=dist_m_1[`i']
	}
matrix list margingraph
matrix colnames margingraph = xm0 distm0 xm1 distm1
* Saves data in CSV file to used by PMB_figures.tex to create histogram
mat2txt2 margingraph using "margin_graph_by_placedballots.csv", replace comma
 
*********************************************************************************
*Figure 4: Histogram of list safety for placed a bill on the ballot or not
*********************************************************************************
twoway (histogram list_margin if placed_b==0 & listseat~=., color(green)) ///
 (histogram list_margin if placed_b==1 & listseat~=.,  fcolor(none) lcolor(black)), legend(order(1 "No" 2 "Yes" ))
* Output for Latex
twoway__histogram_gen list_margin if placed_b==0 & listseat~=.,  start(-34) width(2) gen(dist_lm_0 x0)
twoway__histogram_gen list_margin if placed_b==1 & listseat~=.,  start(-34) width(2) gen(dist_lm_1 x1) 
matrix listgraph=J(41,4,.)
forvalues i=1/41 {
	matrix listgraph[`i',1]=x0[`i']
	matrix listgraph[`i',2]=dist_lm_0[`i']
	matrix listgraph[`i',3]=x1[`i']
	matrix listgraph[`i',4]=dist_lm_1[`i']
	}
matrix list listgraph
matrix colnames listgraph = x0 distlm0 x1 distlm1
* Saves data in CSV file to used by PMB_figures.tex to create histogram
mat2txt2 listgraph using "list_graph_by_placedballots.csv", replace comma


**** Logit Models

logit placed_ballot c.margin##c.list_margin smd_only list_only i.govt support ranked_member seniority timeleft i.year if minister==0, cluster(id)

logit placed_ballot c.margin c.list_margin c.margin#c.list_margin smd_only list_only i.govt c.margin#i.govt support ranked_member seniority timeleft i.year if minister==0, cluster(id)


* Get data for interaction margin plots
margins, dydx(list_margin) at(margin=(-.3(.05).3))

matrix m_lm=r(b)'
matrix v=vecdiag(r(V))'
matmap v se, map(sqrt(@))
matrix m_lm_u=m_lm+1.96*se
matrix m_lm_l=m_lm-1.96*se
matrix at=r(at)
matrix at=at[1..13,"margin"]
matrix margins_lm=at,m_lm,m_lm_u,m_lm_l

margins, dydx(margin) at(list_margin=(-30(5)30))
matrix m_m=r(b)'
matrix v=vecdiag(r(V))'
matmap v se, map(sqrt(@))
matrix m_m_u=m_m+1.96*se
matrix m_m_l=m_m-1.96*se
matrix at=r(at)
matrix at=at[1..13,"list_margin"]
matrix margins_lm=margins_lm,at,m_m,m_m_u,m_m_l

matrix colnames margins_lm = margin m_lm m_lm_u m_lm_l listmargin m_m m_m_u m_m_l
matrix list margins_lm
* Saves data in CSV file to used by PMB_figures.tex to create histogram
mat2txt2 margins_lm using "margins_m_lm_sen.csv", comma replace


logit newbill c.margin##c.list_margin smd_only list_only i.govt support ranked_member seniority timeleft drawn_prev firstballot i.year if minister==0, cluster(id)

logit newbill c.margin c.list_margin c.margin#c.list_margin smd_only list_only i.govt c.margin#i.govt support ranked_member seniority timeleft drawn_prev firstballot i.year if minister==0,  cluster(id)


******************************************
*** END:  TABLE 1 & DATA FOR FIGURE 1-5
******************************************


***********************************
*** TABLE 2 & DATA FOR FIGURE 6
***********************************

use "PSRM_table2.dta", clear

*Models with LR-dist - in paper (table 3 -- no. 2 in vers. w/o list placement)
ologit approvemp attempts lrdist jelecmpshand likeMpParty ranked_member i.surveyyear if  minister==0 
*** Calculate p-values for thresholds
forvalues i=1/4 {
	di "P-value for cutoff `i': "2*normal(-abs(_b[/cut`i']/_se[/cut`i']))
	}

ologit approvemp unique lrdist jelecmpshand likeMpParty ranked_member i.surveyyear if  minister==0 
*** Calculate p-values for thresholds
forvalues i=1/4 {
	di "P-value for cutoff `i': "2*normal(-abs(_b[/cut`i']/_se[/cut`i']))
	}
	
ologit approvemp drawn lrdist jelecmpshand likeMpParty ranked_member i.surveyyear if  minister==0 
*** Calculate p-values for thresholds
forvalues i=1/4 {
	di "P-value for cutoff `i': "2*normal(-abs(_b[/cut`i']/_se[/cut`i']))
	}

*** Calculate Predicted Values for different numbers of	drawn bills
*** Figure 6
margins, predict(outcome(`i')) at(drawn=(0 1 2))
matrix pr=r(b)
forvalues i=2/5 {
	margins, predict(outcome(`i')) at(drawn=(0 1 2))
	matrix pr=pr\r(b)
	}
matrix pr=pr,(1\2\3\4\5)
matrix colnames pr = d1 d2 d3 app
matrix list pr
* Saves data in CSV file to used by PMB_figures.tex to create histogram
mat2txt2 pr using "app_PSRM.csv", comma replace


ologit approvemp drawn unique attempts lrdist likeMpParty jelecmpshand ranked_member i.surveyyear  /// 
 if  minister==0
forvalues i=1/4 {

	di "P-value for cutoff `i': "2*normal(-abs(_b[/cut`i']/_se[/cut`i']))
	}
	
ologit approvemp drawn lrdist likeMpParty jelecmpshand ranked_member i.surveyyear  /// 
 if attempts > 0 
 forvalues i=1/4 {
	di "P-value for cutoff `i': "2*normal(-abs(_b[/cut`i']/_se[/cut`i']))
	}

************************************
*** END: TABLE 2 & DATA FOR FIGURE 6
************************************

**********************************************************************
*** TABLE 3: Conditioning on number of attempts - Conditional logit
**********************************************************************

**** Conditioning on number of attempts - Conditional logit (NOW in BODY of TEXT)

ologit approvemp drawn lrdist likeMpParty jelecmpshand ranked_member i.surveyyear  /// 
 if attempts == 1 & minister==0
forvalues i=1/4 {
	di "P-value for cutoff `i': "2*normal(-abs(_b[/cut`i']/_se[/cut`i']))
	}
	
ologit approvemp drawn lrdist likeMpParty jelecmpshand ranked_member i.surveyyear  /// 
 if (attempts == 2 | attempts == 3 | attempts == 4) & minister==0
forvalues i=1/4 {
	di "P-value for cutoff `i': "2*normal(-abs(_b[/cut`i']/_se[/cut`i']))
	}

ologit approvemp drawn lrdist likeMpParty jelecmpshand ranked_member i.surveyyear  /// 
 if unique == 1 & minister==0
forvalues i=1/4 {
	di "P-value for cutoff `i': "2*normal(-abs(_b[/cut`i']/_se[/cut`i']))
	}

ologit approvemp drawn lrdist likeMpParty jelecmpshand ranked_member i.surveyyear  /// 
 if unique == 2 & minister==0
forvalues i=1/4 {
	di "P-value for cutoff `i': "2*normal(-abs(_b[/cut`i']/_se[/cut`i']))
	}

************************************************************************
*** END: TABLE 3: Conditioning on number of attempts - Conditional logit
************************************************************************


************************************************************************
*** BEGIN: APPENDIX A: Summary statistics
************************************************************************
use "PSRM_table1.dta", clear

bysort id: gen n=_n
sum margin if minister==0 & n==1 & margin>0
sum margin list_margin ranked_member govt smd_only list_only if minister==0 & n==1


************************************************************************
*** END: APPENDIX A: Summary statistics
************************************************************************


use "PSRM_appendixB.dta", clear
**********************************************************************
*** TABLE B5: Margin of Victory
*** NOTE: The results here are slightly different from the version 
*** that was conditionally accepted.  The differences are minor and
*** do not alter the substantive conclusion that there is no real 
*** evidence that PMBs affect electoral success.  The manuscript
*** has been updated to reflect these corrected results and uploaded
*** to the dataverse for reference.
**********************************************************************

reg margin c.attempts i.govt ranked_member 

reg margin c.attempts##i.govt ranked_member 

reg margin c.unique i.govt ranked_member 

reg margin c.unique##i.govt ranked_member 

reg margin c.drawn i.govt ranked_member 

reg margin c.drawn##i.govt ranked_member 

**********************************************************************
*** END: TABLE B5: Margin of Victory
**********************************************************************

**********************************************************************
*** TABLE B6: Margin of Victory by Year
**********************************************************************

reg margin c.attempts##i.govt ranked_member if year==1999
reg margin c.attempts##i.govt ranked_member if year==2002
reg margin c.attempts##i.govt ranked_member if year==2005
reg margin c.attempts##i.govt ranked_member if year==2008
reg margin c.drawn##i.govt ranked_member if year==1999
reg margin c.drawn##i.govt ranked_member if year==2002
reg margin c.drawn##i.govt ranked_member if year==2005
reg margin c.drawn##i.govt ranked_member if year==2008

**********************************************************************
*** END: TABLE B6: Margin of Victory by Year
**********************************************************************

**********************************************************************
*** TABLE B7: Margin of Victory by Year
**********************************************************************

reg margin c.attempts##i.govt ranked_member i.party_no##i.year if (party_no==8 | party_no==7)
reg margin c.unique##i.govt ranked_member i.party_no##i.year if (party_no==8 | party_no==7)
reg margin c.drawn##i.govt ranked_member i.party_no##i.year if (party_no==8 | party_no==7)

**********************************************************************
*** END: TABLE B7: Margin of Victory by Year
**********************************************************************

**********************************************************************
*** TABLE B8: Margin of Victory by Year by no. attempts
**********************************************************************

reg margin c.drawn##i.govt ranked_member if attempts<6
reg margin c.drawn##i.govt ranked_member if attempts>5 & attempts<11
reg margin c.drawn##i.govt ranked_member if attempts>10 

**********************************************************************
*** END: TABLE B8: Margin of Victory by Year by no. attempts
**********************************************************************

**********************************************************************
*** TABLE B9: Change in Margin of Victory 
**********************************************************************

reg ch_margin c.attempts i.govt ranked_member 
reg ch_margin c.attempts##i.govt ranked_member 
reg ch_margin c.unique i.govt ranked_member 
reg ch_margin c.uniqu##i.govt ranked_member 
reg ch_margin c.drawn i.govt ranked_member 
reg ch_margin c.drawn##i.govt ranked_member 

**********************************************************************
*** END: TABLE B9: Change in Margin of Victory 
**********************************************************************

**********************************************************************
*** TABLE B10: Change in Margin of Victory by Year
**********************************************************************

reg ch_margin c.attempts##i.govt ranked_member if year==1999
reg ch_margin c.attempts##i.govt ranked_member if year==2002
reg ch_margin c.attempts##i.govt ranked_member if year==2005
reg ch_margin c.attempts##i.govt ranked_member if year==2008

reg ch_margin c.drawn##i.govt ranked_member if year==1999
reg ch_margin c.drawn##i.govt ranked_member if year==2002
reg ch_margin c.drawn##i.govt ranked_member if year==2005
reg ch_margin c.drawn##i.govt ranked_member if year==2008

**********************************************************************
*** END: TABLE B10: Change in Margin of Victory by Year
**********************************************************************

**********************************************************************
*** TABLE B11: Change in Margin of Victory Party-Year Dummies
**********************************************************************

reg ch_margin c.attempts##i.govt ranked_member i.party_no##i.year if (party_no==8 | party_no==7)
reg ch_margin c.unique##i.govt ranked_member i.party_no##i.year if (party_no==8 | party_no==7)
reg ch_margin c.drawn##i.govt ranked_member i.party_no##i.year if (party_no==8 | party_no==7)

**********************************************************************
*** END: TABLE B11: Change in Margin of Victory Party-Year Dummies
**********************************************************************


**********************************************************************
*** TABLE B12: Change in Margin of Victory by No. Attempts
**********************************************************************

reg ch_margin c.drawn##i.govt ranked_member if attempts<6
reg ch_margin c.drawn##i.govt ranked_member if attempts>5 & attempts<11
reg ch_margin c.drawn##i.govt ranked_member if attempts>10 

**********************************************************************
*** END: TABLE B12: Change in Margin of Victory by No. Attempts 
**********************************************************************


*** Use for tables C13-D14
use "PSRM_table2.dta", clear

**********************************************************************
*** TABLE C13: Conditioning on number of attempts - Conditional logit
**********************************************************************

ologit approvemp drawn lrdist likeMpParty jelecmpshand ranked_member i.surveyyear /// 
 if attempts >0 & attempts < 6 & minister==0
forvalues i=1/4 {
	di "P-value for cutoff `i': "2*normal(-abs(_b[/cut`i']/_se[/cut`i']))
	}

ologit approvemp drawn lrdist likeMpParty jelecmpshand ranked_member i.surveyyear /// 
 if attempts >5 & attempts < 11 & minister==0
forvalues i=1/4 {
	di "P-value for cutoff `i': "2*normal(-abs(_b[/cut`i']/_se[/cut`i']))
	}

ologit approvemp drawn lrdist likeMpParty jelecmpshand ranked_member i.surveyyear /// 
 if attempts >10 & minister==0
forvalues i=1/4 {
	di "P-value for cutoff `i': "2*normal(-abs(_b[/cut`i']/_se[/cut`i']))
	}

**********************************************************************
*** TABLE C13: Conditioning on number of attempts - Conditional logit
**********************************************************************


********************************************************************
*** TABLE D14: Knows MP name
********************************************************************
**** Conditioning on number of attempts (ranges) - Conditional logit II (Appendix)

logit knowsmp attempts lrdist jelecmpshand likeMpParty ranked_member i.surveyyear if  minister==0 
 
logit knowsmp unique lrdist jelecmpshand likeMpParty ranked_member i.surveyyear if  minister==0 

logit knowsmp drawn lrdist jelecmpshand likeMpParty ranked_member i.surveyyear if  minister==0 

logit knowsmp drawn unique attempts lrdist likeMpParty jelecmpshand ranked_member i.surveyyear  /// 
 if  minister==0

logit knowsmp drawn lrdist likeMpParty jelecmpshand ranked_member i.surveyyear  /// 
 if attempts > 0 

********************************************************************
*** END: TABLE D14: Knows MP name
********************************************************************


********************************************************************
*** TABLE E15: Approval: Ideologically close 
*** NOTE: These results (E15-17) were not included in the appendix of the
*** manuscript that was conditionally accepted but are included
*** now in response to one of the referee's suggestion.
********************************************************************

ologit approvemp attempts lrdist jelecmpshand likeMpParty ranked_member i.surveyyear if  minister==0 & lrdist<3
forvalues i=1/4 {
	di "P-value for cutoff `i': "2*normal(-abs(_b[/cut`i']/_se[/cut`i']))
	}

ologit approvemp unique lrdist jelecmpshand likeMpParty ranked_member i.surveyyear if  minister==0 & lrdist<3 
forvalues i=1/4 {
	di "P-value for cutoff `i': "2*normal(-abs(_b[/cut`i']/_se[/cut`i']))
	}

ologit approvemp drawn lrdist jelecmpshand likeMpParty ranked_member i.surveyyear if  minister==0 & lrdist<3 
forvalues i=1/4 {
	di "P-value for cutoff `i': "2*normal(-abs(_b[/cut`i']/_se[/cut`i']))
	}

ologit approvemp drawn unique attempts lrdist likeMpParty jelecmpshand ranked_member i.surveyyear  /// 
	if  minister==0 & lrdist<3
forvalues i=1/4 {
	di "P-value for cutoff `i': "2*normal(-abs(_b[/cut`i']/_se[/cut`i']))
	}

ologit approvemp drawn lrdist likeMpParty jelecmpshand ranked_member i.surveyyear  /// 
	if attempts > 0 & lrdist<3 
forvalues i=1/4 {
	di "P-value for cutoff `i': "2*normal(-abs(_b[/cut`i']/_se[/cut`i']))
	}

 
********************************************************************
*** END: TABLE E15: Approval: Ideologically close 
********************************************************************

********************************************************************
*** TABLE E16: Approval: Ideologically far 
********************************************************************
 
ologit approvemp attempts lrdist jelecmpshand likeMpParty ranked_member i.surveyyear if  minister==0 & lrdist>=3
forvalues i=1/4 {
	di "P-value for cutoff `i': "2*normal(-abs(_b[/cut`i']/_se[/cut`i']))
	}

ologit approvemp unique lrdist jelecmpshand likeMpParty ranked_member i.surveyyear if  minister==0 & lrdist>=3 
forvalues i=1/4 {
	di "P-value for cutoff `i': "2*normal(-abs(_b[/cut`i']/_se[/cut`i']))
	}

ologit approvemp drawn lrdist jelecmpshand likeMpParty ranked_member i.surveyyear if  minister==0 & lrdist>=3 
forvalues i=1/4 {
	di "P-value for cutoff `i': "2*normal(-abs(_b[/cut`i']/_se[/cut`i']))
	}

ologit approvemp drawn unique attempts lrdist likeMpParty jelecmpshand ranked_member i.surveyyear  /// 
 if  minister==0 & lrdist>=3
forvalues i=1/4 {
	di "P-value for cutoff `i': "2*normal(-abs(_b[/cut`i']/_se[/cut`i']))
	}

ologit approvemp drawn lrdist likeMpParty jelecmpshand ranked_member i.surveyyear  /// 
 if attempts > 0 & lrdist>=3
forvalues i=1/4 {
	di "P-value for cutoff `i': "2*normal(-abs(_b[/cut`i']/_se[/cut`i']))
	}
 
********************************************************************
*** END: TABLE E16: Approval: Ideologically far 
********************************************************************

********************************************************************
*** TABLE E17: Approval: Ideologically very far 
********************************************************************

ologit approvemp attempts lrdist jelecmpshand likeMpParty ranked_member i.surveyyear if  minister==0 & lrdist>5
forvalues i=1/4 {
	di "P-value for cutoff `i': "2*normal(-abs(_b[/cut`i']/_se[/cut`i']))
	}

ologit approvemp unique lrdist jelecmpshand likeMpParty ranked_member i.surveyyear if  minister==0 & lrdist>5 
forvalues i=1/4 {
	di "P-value for cutoff `i': "2*normal(-abs(_b[/cut`i']/_se[/cut`i']))
	}

ologit approvemp drawn lrdist jelecmpshand likeMpParty ranked_member i.surveyyear if  minister==0 & lrdist>5 
forvalues i=1/4 {
	di "P-value for cutoff `i': "2*normal(-abs(_b[/cut`i']/_se[/cut`i']))
	}

ologit approvemp drawn unique attempts lrdist likeMpParty jelecmpshand ranked_member i.surveyyear  /// 
 if  minister==0 & lrdist>5
forvalues i=1/4 {
	di "P-value for cutoff `i': "2*normal(-abs(_b[/cut`i']/_se[/cut`i']))
	}

ologit approvemp drawn lrdist likeMpParty jelecmpshand ranked_member i.surveyyear  /// 
 if attempts > 0 & lrdist>5
forvalues i=1/4 {
	di "P-value for cutoff `i': "2*normal(-abs(_b[/cut`i']/_se[/cut`i']))
	}


********************************************************************
*** END: TABLE E17: Approval: Ideologically very far 
********************************************************************


log close
